local Globals = require('lua.vm.Globals')
local FileOutputStream = require('lua.io.FileOutputStream')
local GlobalsUnDumper = require('lua.vm.GlobalsUnDumper')
local LuaCompiler = require('lua.vm.compiler.LuaCompiler')
local LuaLoader = require('lua.vm.compiler.LuaLoader')
local CfgState = require('lua.cfg.CfgState')
local Lua = require('lua.vm.Lua')

local workDir = 'E:\\lua Project\\'
local inputPath = workDir .. 'demo2.lua'
local outputPath = workDir .. 'cfg.dot'
local globals = Globals:new()
globals:installCompiler(LuaCompiler)
globals:installLoader(LuaLoader)
globals:installUnDumper(GlobalsUnDumper)
local f = globals:loadfile(inputPath)
local p = f:checkClosure().p.p[1].p[2]
local state = CfgState:new(p.code)
local g = state:analyze()
local fos = FileOutputStream:new(outputPath)
fos:writeString(g:toDotString())
fos:close()